# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: leon

import datetime
from coin.exchange.base.kr_rest.currency import NativeCurrency
from coin.exchange.uniswap_v3.kr_rest.constants import (
    currency_list,
    quote_currency_list)


def to_native_currency(currency_str: str, current_datetime: datetime.datetime):
  native_currency_str = currency_str
  # assert native_currency_str in currency_list + quote_currency_list, native_currency_str
  return native_currency_str


def from_native_currency(native_currency_str: str, current_datetime: datetime.datetime):
  # assert native_currency_str in currency_list + quote_currency_list, native_currency_str
  currency_str = native_currency_str
  return currency_str


class UniswapCurrency(NativeCurrency):
  _exchange = "Uniswap"

  def __init__(self, currency, native_currency):
    assert currency.upper() == currency, (currency, native_currency)
    assert native_currency.upper() == native_currency, (currency, native_currency)
    assert '-' not in currency, currency
    assert '-' not in native_currency, native_currency
    super().__init__(currency, native_currency)

  @classmethod
  def FromStrCurrencyImpl(cls, currency_str, current_datetime):
    assert isinstance(currency_str, str), type(currency_str)
    return UniswapCurrency(currency_str, to_native_currency(currency_str, current_datetime))

  @classmethod
  def FromStrNativeCurrencyImpl(cls, native_currency_str, current_datetime):
    assert isinstance(native_currency_str, str), native_currency_str
    return UniswapCurrency(from_native_currency(native_currency_str, current_datetime),
                           native_currency_str)
